package com.base.llpark.presenter;

import android.app.Activity;

import com.base.commonlib.base.presenter.BasePresenter;
import com.base.commonlib.http.Api;
import com.base.commonlib.http.BaseResponse;
import com.base.commonlib.utils.RetrofitUtils;
import com.base.llpark.bean.LlPark;
import com.base.llpark.view.ParkDetailView;

import org.json.JSONException;
import org.json.JSONObject;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by weikailiang on 2019/10/26.
 */

public class ParkDetailPresenter extends BasePresenter<ParkDetailView>{

    public ParkDetailPresenter(ParkDetailView view, Activity activity) {
        super(view, activity);
    }
    //上报
    public void ReportLLpark(LlPark park){
        if (park.getState().equals("-1")){
            mView.showMes("请先保存");
            return;
        }
        mView.showPb();
        JSONObject jsobj = new JSONObject();
        try {
            jsobj.put("id",park.getId());
            jsobj.put("state",park.getState());
        } catch (JSONException e) {
            e.printStackTrace();
        }
        Api.getDefault(1).ReportLlPark(RetrofitUtils.createPartFromJson(jsobj.toString())).enqueue(new Callback<BaseResponse<String>>() {
            @Override
            public void onResponse(Call<BaseResponse<String>> call, Response<BaseResponse<String>> response) {
                mView.hidePb();
                if (response.body().getStatus()==1){
                    mView.showMes(response.body().getData());
                    mView.returnReportSuccess();
                }else{
                    mView.showMes(response.body().toString());
                }
            }

            @Override
            public void onFailure(Call<BaseResponse<String>> call, Throwable t) {
                mView.hidePb();
                mView.showMes(t.toString());
            }
        });
    }
}
